package com.openx.xframework.common.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import org.springframework.http.HttpStatus;

import java.util.Date;
import java.util.List;

/**
 * Created by xu on 2017/7/20.
 */
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class ErrorInfo<M> {
    private String path;
    private HttpStatus status;
    private Integer code;
    private String message;
    private Date timestamp;

    private M details;

    public ErrorInfo() {
    }

    public ErrorInfo(String message) {
        this.message = message;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public HttpStatus getStatus() {
        return status;
    }

    public void setStatus(HttpStatus status) {
        this.status = status;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Date getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }

    public M getDetails() {
        return details;
    }

    public void setDetails(M details) {
        this.details = details;
    }

    public static ErrorInfo<List<ParameterError>> ParameterError(String path, List<ParameterError> errors, String message) {
        ErrorInfo error = new ErrorInfo();
        error.setStatus(HttpStatus.BAD_REQUEST);
        error.setMessage(message);
        error.setPath(path);
        error.setDetails(errors);
        error.setTimestamp(new Date());
        return error;
    }

    public static ErrorInfo serverError(String path,HttpStatus status, String message) {
        ErrorInfo error = new ErrorInfo();
        error.setStatus(status);
        error.setMessage(message);
        error.setPath(path);
        error.setTimestamp(new Date());
        return error;
    }
}
